<template>
  <div class="login">
    <!-- <div class="left-wrap" :style="{ backgroundImage: `url(${lfBg})` }">
      <svg class="icon" aria-hidden="true">
        <use xlink:href="#iconzhaopian-copy"></use>
      </svg>

      <img class="left-img" src="@/assets/img/lf_icon.svg" />
    </div>  -->

    <div class="right-wrap">
      <div class="login-wrap">
        <div class="form">
          <h3>登 录</h3>

          <el-col style="margin-top: 30px">
            <span class="input-label">学号</span>
            <el-input
              placeholder="请输入学号"
              size="medium"
              v-model.trim="xuehao"
            />
          </el-col>
          <el-col style="margin-top: 15px">
            <span class="input-label">密码</span>
            <el-input
              placeholder="请输入密码(5~20)"
              size="medium"
              v-model.trim="password"
              type="password"
              autocomplete="off"
              @keyup.enter.native="login"
            />
          </el-col>

          <el-col style="margin-top: 30px">
            <el-button class="login-btn" @click="login" :loading="loading">
              {{ btnText }}
            </el-button>
          </el-col>
          <div class="gologincover">
            <router-link to="/register" class="gologin">前往注册</router-link>
            <router-link to="/findPassword" class="findPassword"
              >重置密码</router-link
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getLogin } from "../../api/data";
import { handleRouter } from "../../router";
export default {
  data() {
    return {
      isNum: 60, // 倒计时
      password: "",
      xuehao: "",
      backgroundImage: require("@/assets/img/login_form_bg.jpg"),
      lfBg: require("@/assets/img/lf_bg.png"),
      loading: false,
      btnText: "登录",
      timer: null,
    };
  },



  methods: {
    // 登录
    async login() {
      let { xuehao, password } = this;

      if (!password) {
        this.$message.error("请输入密码");
        return;
      }
      if (password.length < 5 || password.length > 20) {
        return this.$message.error("密码长度要求5~20个字符");
      }
      if (xuehao.length != 9) {
        this.$message.error("请输入有效学号");
        return;
      }

      let data = await getLogin({
        xuehao,
        password,
      });
      if (data.code == 200) {
        // 保存登陆信息
        // console.log(data.data)
        this.$store.commit("setuserdata", data.data);
        this.$store.commit("settoken", data.token);

        // 保存token
        sessionStorage.setItem("token", data.token);
        // 登陆成功 动态渲染路由
        this.$message.success(data.msg);
        handleRouter(data.data.user_jurisdiction_routerlist);

        // 将路由信息单独保存
        sessionStorage.setItem(
          "routerlist",
          JSON.stringify(data.data.user_jurisdiction_routerlist)
        );

        this.$router.push("/");
        this.$message.success(data.msg);

        this.isTrue = false;
        this.isNum = 60;
        this.code = "";
        clearInterval(this.timer);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100vh;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;

  .icon {
    width: 32px;
    height: 32px;
  }

  .el-input__inner {
    &:focus {
      border: 1px solid #4e83fd;
    }
  }

  .el-input--medium .el-input__inner {
    height: 40px;
    line-height: 40px;
  }

  .left-wrap {
    width: 520px;
    height: 100%;
    background: #fff;
    background-size: cover;
    padding: 20px;
    box-sizing: border-box;

    .left-img {
      display: block;
      margin: auto;
      margin-top: 300px;
    }
  }

  .right-wrap {
    width: calc(100% - 520px);
    height: 100%;
    position: relative;

    .header {
      display: none;
    }

    .login-wrap {
      width: 440px;
      height: 450px;
      border-radius: 5px;
      overflow: hidden;
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      margin: auto;
      background-size: cover;
      box-shadow: 0 0 10px rgba(28, 76, 186, 0.1);
      // background-color: none;

      .form {
        widows: 100%;
        height: 100%;
        box-sizing: border-box;
        padding: 50px 30px;
        background: #fff;

        h3 {
          color: #fff;
          font-size: 26px;
          text-align: center;
          font-weight: 500;
        }

        .input-label {
          color: #333;
          font-size: 14px;
          padding: 8px 0;
          display: block;
        }

        .code {
          display: flex;
          justify-content: space-between;

          .el-input {
            flex: 1;
            margin-right: 20px;
          }

          img {
            width: 115px;
            height: 40px;
            cursor: pointer;
            border-radius: 5px;
            // background: #f8f8f8 !important;
          }
        }

        .login-btn {
          width: 100%;
          height: 40px;
          border: 0;
          color: #fff;
          background: #4e83fd;
        }
      }
    }
  }
}

@media only screen and (max-width: 1200px) {
  .login {
    width: 100%;
    height: 100vh;

    .left-wrap {
      display: none;
    }

    .right-wrap {
      width: 100%;

      .header {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 20vh;

        h1 {
          font-weight: 500;
          margin-left: 15px;
        }
      }

      .login-wrap {
        width: 100%;
        height: 100vh;
        border-radius: 0;
        position: relative;
        box-shadow: none;
        .mima {
          margin-top: 30px !important;
        }

        .form {
          padding: 0px 30px;

          // h3 {
          //   display: none;
          // }
        }
      }
    }
  }
}
.handleyzm {
  height: 36px;
  line-height: 36px;
  text-align: center;
  padding: 0 15px;
  // background-color: #f3f4fb;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  color: #444;
}

.code {
  display: flex;
  align-items: center;
}

.form {
  position: relative;
  .mima {
    // position: absolute;
    // bottom: 10px;
    // left: 50%;
    // transform: translate(-50%, 0);
    display: block;
    height: 40px;
    line-height: 40px;
    text-align: center;

    font-size: 14px;
    color: #999;
    cursor: pointer;
    &:hover {
      color: #369;
    }
  }
}

.gologincover {
  text-align: center;
  height: 50px;
  line-height: 50px;
  .gologin {
    // position: relative;
    // top: 20px;
    text-decoration: none;
    color: #999;
    margin-right: 20px;
    &:hover {
      color: #4e83fd;
    }
  }
  .findPassword {
    text-decoration: none;
    color: #999;
    &:hover {
      color: #4e83fd;
    }
  }
}

.form{
  background-color: none !important;
}
// .el-button{
//   background: none !important;
//   color: #333 !important;
//   &:hover{
//     background-color: #4e83fd !important;
//     color: #fff !important;
//   }
// }
</style>
